import vue from '@vitejs/plugin-vue';
const { resolve } = require('path');
import { defineConfig } from 'vite';

export default defineConfig(({ command }) => {
	return {
		base: './',
		plugins: [vue()],
		optimizeDeps: {
			include: ['schart.js'],
		},
		resolve: {
			alias: {
				'@': resolve(__dirname, './src'), // 设置为@ 则使用时为 "@/components/index.module.css"
				'@components': resolve(__dirname, './src/components'), // 使用时为 "@components/HelloWorld.vue"
			},
		},
		build: {
			minify: 'terser', // 默认为 Esbuild，它比 terser 快 20-40 倍，压缩率只差 1%-2%，出于使用drop_console，故选用terser
			terserOptions: {
				/**
				 * command 用来判断环境
				 */
				compress: {
					drop_console: command !== 'serve',
					// 默认是true
					drop_debugger: command !== 'serve',
				},
			},
		},
		hmr: { overlay: false },
		define: {
			'process.env': {},
		},
		//解决打包警告 <stdin>:132:1: warning: "@charset" must be the first rule in the file
		css: {
			postcss: {
				plugins: [
					{
						postcssPlugin: 'internal:charset-removal',
						AtRule: {
							charset: (atRule) => {
								if (atRule.name === 'charset') {
									atRule.remove();
								}
							},
						},
					},
				],
			},
		},
		//解决打包警告 end
	};
});
